package org.slf4j.impl;

import org.slf4j.ILoggerFactory;
import org.slf4j.Logger;

import java.io.FileNotFoundException;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

public class LoggerFactory implements ILoggerFactory {

    ConcurrentMap<String, Logger> stringLoggerConcurrentMap;

    public LoggerFactory() {
        stringLoggerConcurrentMap = new ConcurrentHashMap<String, Logger>();
    }

    @Override
    public Logger getLogger(String name) {
        com.db.logging.Logger myLogger = null;

        try {
            myLogger = new com.db.logging.Logger(name);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        Logger newInstance = new LoggerAdapter(myLogger);
        Logger oldInstance =
                stringLoggerConcurrentMap.putIfAbsent(name, newInstance);

        if (oldInstance == null) {
            return newInstance;
        } else {
            return oldInstance;
        }
    }

}
